<?php
class ControllerAccountActivate extends Controller {
    private $error = array();

    public function index() {

        $this->load->model('account/customer');
        $this->language->load('account/activate');

        $array = explode('|',base64_decode($_GET['a']));

        $email=$array['0'];
        $salt=$array['1'];

        if($array) {
            $result=$this->model_account_customer->getunactivateCustomer($array['0'],$array['1']);
            if(!$result){
                $this->redirect($this->url->link('account/account', '', 'SSL'));
            }else{
                setcookie("guide", '1');
                //同步到后台
                $this->backend->register_user($result['email'], $result['password_plain']);
//                $this->backend->recharge($result['email'],$result['password_plain'],10);
                $this->model_account_customer->activateCustomer($array['0'],$array['1']);
                $this->customer->login($result['email'], $result['password_plain']);
            }
        }else{
            $this->redirect($this->url->link('account/account', '', 'SSL'));
        }
        $this->document->setTitle($this->language->get('heading_title'));

        $this->data['breadcrumbs'] = array();

        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home'),
            'separator' => false
        );

        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_account'),
            'href'      => $this->url->link('account/account', '', 'SSL'),
            'separator' => $this->language->get('text_separator')
        );

        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_forgotten'),
            'href'      => $this->url->link('account/forgotten', '', 'SSL'),
            'separator' => $this->language->get('text_separator')
        );

        $this->data['heading_title'] = $this->language->get('heading_title');

        $this->data['text_success'] = $this->language->get('text_success');

        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }

        $this->data['action'] = $this->url->link('account/forgotten', '', 'SSL');

        $this->data['back'] = $this->url->link('account/login', '', 'SSL');

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/activate.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/account/activate.tpl';
        } else {
            $this->template = 'default/template/account/activate.tpl';
        }

        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );

        $this->response->setOutput($this->render());
    }

    protected function validate() {
        if (!isset($this->request->post['email'])) {
            $this->error['warning'] = $this->language->get('error_email');
        } elseif (!$this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
            $this->error['warning'] = $this->language->get('error_email');
        }

        if (!$this->error) {
            return true;
        } else {
            return false;
        }
    }
}
?>